package operation;

import book.Book;
import book.BookShelf;

import java.util.Scanner;

public class AddOperation implements IOperation{
    @Override
    public void working(BookShelf bookShelf) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你要新增图书的名称：");
        String name = scanner.next();

        int currentSize = bookShelf.getUsedSize();
        for (int i = 0; i < currentSize; i++) {
            Book book = bookShelf.getBooks(i);
            if(book.getName().equals(name)){
                System.out.println("这本书已存在");
                System.out.println(book);
                return;
            }
        }


        System.out.println("请输入你要新增图书的作者：");
        String author = scanner.next();

        System.out.println("请输入你要新增图书的价格：");
        int price = scanner.nextInt();

        System.out.println("请输入你要新增图书的类型：");
        String type = scanner.next();

        Book book = new Book(name,author,price,type);
        bookShelf.setBooks(book,currentSize);
        bookShelf.setUsedSize(currentSize+1);
    }
}
